package com.xueyi.aixihu.mapper;

import com.xueyi.aixihu.entity.po.DtAuthRule;
import com.xueyi.aixihu.entity.po.DtNewsSort;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜单Mapper
 */
public interface MenuMapper {

    /**
     * 通过ID查询
     *
     * @param ids
     * @return
     */
    @Select("SELECT * FROM dt_auth_rule WHERE id IN (${ids}) AND status = true AND `name` not like '【%' ")
    List<DtAuthRule> findAuthById(@Param("ids") String ids);

    /**
     * 查询该用户管理的地址信息
     *
     * @param id
     * @return
     */
    @Select("SELECT GROUP_CONCAT(id)  FROM dt_news_sort WHERE id IN ( " +
            "SELECT manage_area_id FROM axh_user_manage_area WHERE user_id = #{id} ) AND is_valid = 1")
    String findUserManageAreaId(Integer id);

    /**
     * 查询该用户管理的地址信息
     *
     * @return
     */
    @Select("SELECT * FROM dt_news_sort WHERE id IN ( " +
            "   SELECT manage_area_id FROM axh_user_manage_area WHERE user_id = #{userId}" +
            "   ) AND is_valid = 1 AND pid = #{addressId} ")
    List<DtNewsSort> findUserManageArea(@Param("userId") Integer userId,
                                        @Param("addressId") Integer addressId);

    @Select({
        " select * from dt_news_sort where is_valid=1 and pid=#{pid}"
    })
    List<DtNewsSort> selectNewsSortByPid(@Param("pid")Integer pid);
}
